package com.office.system.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.office.system.mapper.FinanceExpenseMapper;
import com.office.system.domain.FinanceExpense;
import com.office.system.service.IFinanceExpenseService;
import com.office.common.utils.uuid.Seq;
import java.math.BigDecimal;

/**
 * 支出记录Service业务层处理
 * 
 * @author 数字牧马人
 */
@Service
public class FinanceExpenseServiceImpl implements IFinanceExpenseService 
{
    @Autowired
    private FinanceExpenseMapper financeExpenseMapper;

    /**
     * 查询支出记录
     * 
     * @param expenseId 支出记录主键
     * @return 支出记录
     */
    @Override
    public FinanceExpense selectFinanceExpenseByExpenseId(Long expenseId)
    {
        return financeExpenseMapper.selectFinanceExpenseByExpenseId(expenseId);
    }

    /**
     * 查询支出记录列表
     * 
     * @param financeExpense 支出记录
     * @return 支出记录
     */
    @Override
    public List<FinanceExpense> selectFinanceExpenseList(FinanceExpense financeExpense)
    {
        return financeExpenseMapper.selectFinanceExpenseList(financeExpense);
    }

    /**
     * 新增支出记录
     * 
     * @param financeExpense 支出记录
     * @return 结果
     */
    @Override
    public int insertFinanceExpense(FinanceExpense financeExpense)
    {
        // 生成支出编号
        if (financeExpense.getExpenseNo() == null || financeExpense.getExpenseNo().isEmpty()) {
            financeExpense.setExpenseNo("EXP" + Seq.getId());
        }
        // 设置创建时间
        if (financeExpense.getCreateTime() == null) {
            financeExpense.setCreateTime(new Date());
        }
        return financeExpenseMapper.insertFinanceExpense(financeExpense);
    }

    /**
     * 修改支出记录
     * 
     * @param financeExpense 支出记录
     * @return 结果
     */
    @Override
    public int updateFinanceExpense(FinanceExpense financeExpense)
    {
        return financeExpenseMapper.updateFinanceExpense(financeExpense);
    }

    /**
     * 批量删除支出记录
     * 
     * @param expenseIds 需要删除的支出记录主键
     * @return 结果
     */
    @Override
    public int deleteFinanceExpenseByExpenseIds(Long[] expenseIds)
    {
        return financeExpenseMapper.deleteFinanceExpenseByExpenseIds(expenseIds);
    }

    /**
     * 删除支出记录信息
     * 
     * @param expenseId 支出记录主键
     * @return 结果
     */
    @Override
    public int deleteFinanceExpenseByExpenseId(Long expenseId)
    {
        return financeExpenseMapper.deleteFinanceExpenseByExpenseId(expenseId);
    }

    /**
     * 审批支出记录
     * 
     * @param expenseId 支出记录ID
     * @param status 审批状态
     * @param approver 审批人
     * @return 结果
     */
    @Override
    public int approveExpense(Long expenseId, String status, String approver)
    {
        return financeExpenseMapper.approveExpense(expenseId, status, approver);
    }

    /**
     * 统计支出金额
     * 
     * @param financeExpense 查询条件
     * @return 支出金额
     */
    @Override
    public BigDecimal selectExpenseAmount(FinanceExpense financeExpense)
    {
        return financeExpenseMapper.selectExpenseAmount(financeExpense);
    }

    /**
     * 按分类统计支出
     * 
     * @param financeExpense 查询条件
     * @return 分类统计结果
     */
    @Override
    public List<Map<String, Object>> selectExpenseByCategory(FinanceExpense financeExpense)
    {
        return financeExpenseMapper.selectExpenseByCategory(financeExpense);
    }
} 